;(function(){
/*这是根据屏幕的宽度设置rem的脚本*/
    var suportEvent = "onrientationchange" in window ? "orientationchange" : "resize";
    function setRem() {
        var clientW = document.documentElement.offsetWidth;
        clientW = clientW >= 750 ? 750 : clientW;
        var fontSize = 100 / 375 * clientW;
        document.documentElement.style.fontSize = fontSize + "px";
    }
    window.addEventListener(suportEvent, debounce(setRem));
    window.addEventListener("load",function(){
        setRem();
    });
})();
/*防抖方法*/
function debounce(fn,box, event, delay) {
    var delay = delay || 300;
    var timer = null;
    return function (e) {
        timer && clearTimeout(timer);
        timer = setTimeout(() => {
            fn(box);
        }, delay);
    }
}


/*屏幕改变加载图片的方法 */
function screenChange(selector) {
    var suportEvent = "onrientationchange" in window ? "orientationchange" : "resize";
    window.addEventListener(suportEvent, function () {
        $(window).scroll();
    });
    $(window).scroll(debounce(lazyload, selector));
    lazyload(selector);

    /*加载图片方法 */
    function lazyload(selector) {
        var winH = $(window).height();
        var imgs = selector.find("img[data-src]");
        var len=$("img[data-src]").length;
        if (len == 0) $(window).off("scroll");
        var scrollH = $(window).scrollTop();
        $.each(imgs, function (index, item) {
            var imgTop = $(item).offset().top;
            var imgH = $(item).parent().height();
            if (((imgTop + imgH) >= scrollH) && (imgTop <= (scrollH + winH))) {
                var src = item.getAttribute("data-src");
                item.removeAttribute("data-src");
                item.setAttribute("src", src);
            }
        });
    }
}

/*轮播图方法*/
function bannar() {
        /*调用轮播图*/
        var mySwiper = new Swiper('.swiper-container', {
            autoplay: true,
            loop: true,
            pagination: {
                el: '.swiper-pagination',
            },
            autoplay: {
                disableOnInteraction: false,
            }
        });
}

/*切换图片函数*/
function unfold(selector,second){ 
    var event="onclick" in window?"click":"tap";
    selector.on(event,function(){
        if (selector.hasClass("unfold"))return;
        selector.addClass("unfold").siblings().removeClass("unfold");
        second.addClass("unfold").siblings().removeClass("unfold");
       second.find("img[data-src]").length>0&&screenChange(second);
    });
}
